<template>
	<div class="card-page">
		<tool-bar nav="" :title="action_name + 'mobileCodeLog'">
			<el-button size="small" @click="$router.push('/log/mobile-code-log/add')" v-if="$props.action=='edit'">新建</el-button>
			<el-button size="small" @click="save_click" type="primary"> 保存</el-button>
		</tool-bar>
		<el-row :gutter="12" type="flex">
			<el-col :span="12">
				<el-card shadow="always">

                    <template #header> <span>基本信息</span> </template>
					<kv label="module">
						<selector v-model="info.module" enum="MobileCodeModuleEnum" chk="*"/>
					</kv>
					<kv label="mobile">
						<el-input v-model="info.mobile" />
					</kv>
					<kv label="templateCode">
						<el-input v-model="info.templateCode" />
					</kv>
					<kv label="param">
						<el-input v-model="info.param" />
					</kv>
					<kv label="bizId">
						<el-input v-model="info.bizId" />
					</kv>
					<kv label="result">
						<el-input v-model="info.result" />
					</kv>
					<kv label="errorMessage">
						<el-input v-model="info.errorMessage" />
					</kv>
					<kv label="sentAt">
						<el-date-picker v-model="info.sentAt" placeholder="选择日期时间"  type="datetime" />
					</kv>
					<kv label="arrivedAt">
						<el-date-picker v-model="info.arrivedAt" placeholder="选择日期时间"  type="datetime" />
					</kv>
				</el-card>
			</el-col>
			<el-col :span="12">
				<el-card shadow="always">
                    <template #header> <span>扩展信息</span> </template>
				</el-card>
			</el-col>
		</el-row>
	</div>
</template>

<script setup>
/**
 * Created by CodeGenerator  at 2022-02-22 15:33:17
 */




//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();



//定义data
const $data = reactive({
    MobileCodeModuleEnum: jv.enum.MobileCodeModuleEnum.getData(),
    "info":{"result":{}}});
const info = $computed(()=> $data.info );

const $props = defineProps({
    action: { type: String } ,
    id : { type: String }
});

const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","loaded"]);

const action = $computed( function() {
    return $props.id ? "edit" : "add";
});
const action_name = $computed( function() {
    return {add: "添加", edit: "修改"}[$props.action]
});

const loadData = async function() {
    if (!$props.id) return;
    var res = await jv.$http.post("/log/mobile-code-log/detail/" + $props.id)
    $data.info = res.data.data;
};
const save_click = async function() {
//校验
    if (jv.chk_main($data) == false) {
        return;
    }
    var res =await jv.$http.post("/log/mobile-code-log/save", $data.info)
//[axios拦截器中已处理了异常]。
    jv.info(action_name + " 成功");
    if ($props.action == "add") {
        var id = res.data.data
        jv.setLastRowId("/log/mobile-code-log/list", "list", id);
        jv.$router.push("/log/mobile-code-log/edit/" + id)
    } else if ($props.action == "edit") {
        jv.$router.push("/log/mobile-code-log/list")
    }
};

onMounted( function() {
    loadData();
} )



</script>
